package com.qinggeng.project.system.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.UserMessage;
import com.qinggeng.project.system.service.IUserAliasService;
import com.qinggeng.project.system.service.IUserMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 消息列Controller
 *
 * @author qinggeng
 * @date 2020-06-30
 */
@RestController
@RequestMapping("/system/systemMessage")
public class UserMessageController extends BaseController
{
    @Autowired
    private IUserMessageService userMessageService;

    @Autowired
    private IUserAliasService userAliasService;

    /**
     * 查询消息列列表
     */
    @PreAuthorize("@ss.hasPermi('system:systemMessage:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserMessage userMessage)
    {
        startPage();
        List<UserMessage> list = userMessageService.selectUserMessageList(userMessage);
        return getDataTable(list);
    }

    /**
     * 导出消息列列表
     */
    @PreAuthorize("@ss.hasPermi('system:systemMessage:export')")
    @Log(title = "消息列", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserMessage userMessage)
    {
        List<UserMessage> list = userMessageService.selectUserMessageList(userMessage);
        ExcelUtil<UserMessage> util = new ExcelUtil<UserMessage>(UserMessage.class);
        return util.exportExcel(list, "systemMessage");
    }

    /**
     * 获取消息列详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:systemMessage:query')")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") Long messageId)
    {
        return AjaxResult.success(userMessageService.selectUserMessageById(messageId));
    }

    /**
     * 新增消息列
     */
    @PreAuthorize("@ss.hasPermi('system:systemMessage:add')")
    @Log(title = "消息列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserMessage userMessage)
    {
        userMessage.setMessageType("10");
        userMessage.setUserId(0l);
        return toAjax(userMessageService.insertUserMessage(userMessage));
    }

    /**
     * 修改消息列
     */
    @PreAuthorize("@ss.hasPermi('system:systemMessage:edit')")
    @Log(title = "消息列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserMessage userMessage)
    {
        return toAjax(userMessageService.updateUserMessage(userMessage));
    }

    /**
     * 删除消息列
     */
    @PreAuthorize("@ss.hasPermi('system:systemMessage:remove')")
    @Log(title = "消息列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable Long[] messageIds)
    {
        return toAjax(userMessageService.deleteUserMessageByIds(messageIds));
    }



}
